package com.bawei.common.dialog

import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.WindowManager
import android.widget.ImageView
import androidx.appcompat.app.AppCompatDialog
import com.bawei.common.R

/**
 * Author: Jason Zhang
 * Date: 2024/4/28
 * Desc: App版本更新Dialog
 */
class AppUpdateDialog: AppCompatDialog {

    constructor(context: Context): super(context){

    }

    constructor(context: Context, theme: Int): super(context, theme){

    }

    constructor(context: Context, cancelable: Boolean, cancelListener: DialogInterface.OnCancelListener): super(context, cancelable, cancelListener){

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.app_update_layout)
        //设置取消按钮点击事件
        findViewById<ImageView>(R.id.iv_cancel)?.setOnClickListener {
            cancel()
        }

        //获取布局属性参数，修改宽高大小
        var windowParams: WindowManager.LayoutParams? = window?.attributes
        windowParams?.apply {
            dimAmount = 0.3f //灰色区域暗度
            width = WindowManager.LayoutParams.MATCH_PARENT
            height = WindowManager.LayoutParams.MATCH_PARENT
        }
        //重新赋值
        window?.attributes = windowParams
        //设置透明背景
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

        //设置可以取消
        setCanceledOnTouchOutside(false)
        setCancelable(true)
    }

}